package com.example.showlocation;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.Looper;
import android.util.Log;

import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;

public class BindRequestSingleFreshLocationService extends Service {
    TencentLocationManager locationManager;
    TencentLocationRequest locationRequest;
    double latitude;
    double longitude;
    boolean indentif;
    class MyLocationListener implements TencentLocationListener {
        @Override
        public void onLocationChanged(TencentLocation tencentLocation, int error, String reason) {
            latitude=tencentLocation.getLatitude();
            longitude=tencentLocation.getLongitude();
            indentif=true;
            Log.d(this.toString()+":", tencentLocation.getLatitude()+","+tencentLocation.getLongitude());
            Log.d(this.toString()+":", "onLocationChanged");
        }

        @Override
        public void onStatusUpdate(String s, int i, String s1) {

        }

    }

    public void RequestSingleFreshLocation() {


        locationManager = TencentLocationManager.getInstance(this);
        locationRequest = TencentLocationRequest.create();
        locationRequest.setGpsFirst(true);
        MyLocationListener mLocationListener=new MyLocationListener();
        TencentLocationManager.setUserAgreePrivacy(true);
        locationManager.requestSingleFreshLocation(locationRequest,mLocationListener , Looper.myLooper());

        Log.d(this.toString()+":", "RequestSingleFreshLocation");
    }
    // Binder given to clients
    private final IBinder binder = new LocalBinder();
    // Random number generator


    /**
     * Class used for the client Binder.  Because we know this service always
     * runs in the same process as its clients, we don't need to deal with IPC.
     */
    public class LocalBinder extends Binder {
        BindRequestSingleFreshLocationService getService() {
            // Return this instance of LocalService so clients can call public methods
            return BindRequestSingleFreshLocationService.this;
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        return binder;


    }


}